package com.coffee.test.server;

import com.coffee.netty.RpcCodec;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;

/**
 * @author songkui
 * @since 2024/8/5 16:14
 */
public class HjCoder implements RpcCodec {
    @Override
    public ChannelHandler packDecoder() {
        ByteBuf delimiter = Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8);
        return new DelimiterBasedFrameDecoder(2048, delimiter);
    }

    @Override
    public ChannelHandler encoder() {
        return  new StringEncoder(CharsetUtil.UTF_8);
    }

    @Override
    public ChannelHandler decoder() {
        return  new StringDecoder(CharsetUtil.UTF_8);
    }
}
